package com.sinopec.basemodule.widget;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.davemorrissey.labs.subscaleview.ImageSource;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.sinopec.basemodule.R;

/**
 * ImageView创建工厂
 */
public class ViewFactory {
    /**
     * 获取ImageView视图的同时加载显示url
     */
    public static View getView(Context context, int lineResId, int iconResId, String text, boolean showButton, final ClickListener listener) {
        View view = LayoutInflater.from(context).inflate(
                R.layout.view_banner, null);
        SubsamplingScaleImageView ivLine = view.findViewById(R.id.iv_line);
        SubsamplingScaleImageView ivIcon = view.findViewById(R.id.iv_icon);
        TextView tvBanner = view.findViewById(R.id.tv_text);
        Button btnToLogin = view.findViewById(R.id.btn_to_login);
        Button btSkip = view.findViewById(R.id.bt_skip);
        if (lineResId!=-1){
            ivLine.setImage(ImageSource.resource(lineResId));
        }
        ivIcon.setImage(ImageSource.resource(iconResId));
        tvBanner.setText(text);
        if (showButton) {
            btnToLogin.setVisibility(View.VISIBLE);
            btnToLogin.setOnClickListener(view1 -> listener.click());
        }
        btSkip.setOnClickListener(view12 -> listener.click());
        return view;
    }

    public interface ClickListener {
        void click();
    }
}
